package dao;

import util.DBConnection;
import vo.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    User user = null;
    Connection con = DBConnection.getInstance();


    public User findUserByAccountAndPassword(String account,String password) throws SQLException {
        System.out.println(account+"-->"+password);

        PreparedStatement pest = con.prepareStatement("select * from users where user_account=? and user_password=?");
        pest.setString(1,account);
        pest.setString(2,password);

        ResultSet rest = null;
        rest = pest.executeQuery();
        System.out.println(rest);
        while (rest.next()){
            String id = rest.getString(1);
            String ac = rest.getString(2);
            String pwd = rest.getString(3);
            String name = rest.getString(4);

            user = new User(id,ac,pwd,name);

        }



        return user;
    }

}
